﻿using System.ComponentModel;
using System.Drawing;
using System;

namespace demo_cs
{
    internal class Cvars
    {
        private CvarWrapper _r_wireframe_color;        
        private CvarWrapper _r_width;
        private CvarWrapper _r_height;        
        private CvarWrapper _r_clip;

        private CvarWrapper _s_wireframe_color_selected;
        private CvarWrapper _s_active_camera;
        private CvarWrapper _s_active_model;
        private CvarWrapper _s_axis;
        private CvarWrapper _s_grid;

        private CvarWrapper _m_axis;
        private CvarWrapper _m_transform_type;        
        private CvarWrapper _m_bounding_box;
        private CvarWrapper _m_bounding_box_color;
        private CvarWrapper _m_face_normals;
        private CvarWrapper _m_face_normal_size;
        private CvarWrapper _m_face_normal_color;
        private CvarWrapper _m_vertex_normals;
        private CvarWrapper _m_vertex_normal_size;
        private CvarWrapper _m_vertex_normal_color;

        private CvarWrapper _c_type;
        private CvarWrapper _c_transform_type;
        private CvarWrapper _c_mark;
        private CvarWrapper _c_mark_size;
        private CvarWrapper _c_mark_color;
        private CvarWrapper _c_left;
        private CvarWrapper _c_right;
        private CvarWrapper _c_bottom;
        private CvarWrapper _c_top;
        private CvarWrapper _c_near;
        private CvarWrapper _c_far;
        private CvarWrapper _c_fov_y;
        private CvarWrapper _c_zoom;

        private CvarWrapper _i_mouse_sensitivity;

        public Cvars(DemoContext demo)
        {
            _r_wireframe_color = demo.GetCvar("r_wireframe_color", true);            
            _r_width = demo.GetCvar("r_width");
            _r_height = demo.GetCvar("r_height");            
            _r_clip = demo.GetCvar("r_clip");

            _s_wireframe_color_selected = demo.GetCvar("s_wireframe_color_selected", true);
            _s_active_camera = demo.GetCvar("s_active_camera", true);
            _s_active_model = demo.GetCvar("s_active_model", true);
            _s_axis = demo.GetCvar("s_axis", true);
            _s_grid = demo.GetCvar("s_grid", true);

            _m_axis = demo.GetCvar("m_aixs", true);
            _m_transform_type = demo.GetCvar("m_transform_type");            
            _m_bounding_box = demo.GetCvar("m_bounding_box", true);
            _m_bounding_box_color = demo.GetCvar("m_bounding_box_color", true);
            _m_face_normals = demo.GetCvar("m_face_normals", true);
            _m_face_normal_size = demo.GetCvar("m_face_normal_size", true);
            _m_face_normal_color = demo.GetCvar("m_face_normal_color", true);            
            _m_vertex_normals = demo.GetCvar("m_vertex_normals", true);
            _m_vertex_normal_size = demo.GetCvar("m_vertex_normal_size", true);
            _m_vertex_normal_color = demo.GetCvar("m_vertex_normal_color", true);

            _c_type = demo.GetCvar("c_type");
            _c_transform_type = demo.GetCvar("c_transform_type");
            _c_left = demo.GetCvar("c_left");
            _c_right = demo.GetCvar("c_right");
            _c_bottom = demo.GetCvar("c_bottom");
            _c_top = demo.GetCvar("c_top");
            _c_fov_y = demo.GetCvar("c_fov_y");
            _c_zoom = demo.GetCvar("c_zoom");            
            _c_mark = demo.GetCvar("c_mark");
            _c_mark_size = demo.GetCvar("c_mark_size");
            _c_mark_color = demo.GetCvar("c_mark_color");
            _c_near = demo.GetCvar("c_near");
            _c_far = demo.GetCvar("c_far");

            _i_mouse_sensitivity = demo.CreateCvar("i_mouse_sensitivity", 0.1f);
        }

        [Category("Renderer")]
        [Description("Model lines color")]
        public Color r_wireframe_color
        {
            get { return Color.FromArgb(_r_wireframe_color.GetValueI()); }
            set { _r_wireframe_color.SetValue(value.ToArgb()); }
        }        

        [Category("Renderer")]
        [Description("Screen width")]
        public int r_width
        {
            get { return _r_width.GetValueI(); }
            set { _r_width.SetValue(value); }
        }

        [Category("Renderer")]
        [Description("Screen height")]
        public int r_height
        {
            get { return _r_height.GetValueI(); }
            set { _r_height.SetValue(value); }
        }

        [Category("Renderer")]
        [Description("Clipping")]
        public bool r_clip
        {
            get { return _r_clip.GetValueB(); }
            set { _r_clip.SetValue(value); }
        }

        [Category("Scene")]
        [Description("Selected model lines color")]
        public Color s_wireframe_color_selected
        {
            get { return Color.FromArgb(_s_wireframe_color_selected.GetValueI()); }
            set { _s_wireframe_color_selected.SetValue(value.ToArgb()); }
        }

        [Category("Scene")]
        [Description("Active camera index")]
        public int s_active_camera
        {
            get { return _s_active_camera.GetValueI(); }
            set { _s_active_camera.SetValue(value); }
        }

        [Category("Scene")]
        [Description("Active model index")]
        public int s_active_model
        {
            get { return _s_active_model.GetValueI(); }
            set { _s_active_model.SetValue(value); }
        }

        [Category("Scene")]
        [Description("Draw axis")]
        public bool s_axis
        {
            get { return _s_axis.GetValueB(); }
            set { _s_axis.SetValue(value); }
        }

        [Category("Scene")]
        [Description("Draw grid")]
        public bool s_grid
        {
            get { return _s_grid.GetValueB(); }
            set { _s_grid.SetValue(value); }
        }

        [Category("Model")]
        [Description("Draw model axis")]
        public bool m_axis
        {
            get { return _m_axis.GetValueB(); }
            set { _m_axis.SetValue(value); }
        }

        [Category("Model")]
        [Description("Model transformation type")]
        public ModelTransfromType m_transfrom_type
        {
            get { return (ModelTransfromType) _m_transform_type.GetValueI(); }
            set { _m_transform_type.SetValue((int)value); }
        }

        [Category("Model")]
        [Description("Draw bounding box")]
        public bool m_bounding_box
        {
            get { return _m_bounding_box.GetValueB(); }
            set { _m_bounding_box.SetValue(value); }
        }

        [Category("Model")]
        [Description("Bounding box color")]
        public Color m_bounding_box_color
        {
            get { return Color.FromArgb(_m_bounding_box_color.GetValueI()); }
            set { _m_bounding_box.SetValue(value.ToArgb()); }
        }

        [Category("Model")]
        [Description("Draw face normals")]
        public bool m_face_normals
        {
            get { return _m_face_normals.GetValueB(); }
            set { _m_face_normals.SetValue(value); }
        }

        [Category("Model")]
        [Description("Face normal size")]
        public float m_face_normal_size
        {
            get { return _m_face_normal_size.GetValueF(); }
            set { _m_face_normal_size.SetValue(value); }
        }

        [Category("Model")]
        [Description("Face normal color")]
        public Color m_face_normal_color
        {
            get { return Color.FromArgb(_m_face_normal_color.GetValueI()); }
            set { _m_face_normal_color.SetValue(value.ToArgb()); }
        }

        [Category("Model")]
        [Description("Draw vertex normals")]
        public bool m_vertex_normals
        {
            get { return _m_vertex_normals.GetValueB(); }
            set { _m_vertex_normals.SetValue(value); }
        }

        [Category("Model")]
        [Description("Vertex normal size")]
        public float m_vertex_normal_size
        {
            get { return _m_vertex_normal_size.GetValueF(); }
            set { _m_vertex_normal_size.SetValue(value); }
        }

        [Category("Model")]
        [Description("Vertex normal color")]
        public Color m_vertex_normal_color
        {
            get { return Color.FromArgb(_m_vertex_normal_color.GetValueI()); }
            set { _m_vertex_normal_color.SetValue(value.ToArgb()); }
        }

        [Category("Camera")]
        [Description("Camera type")]
        public CameraType c_type
        {
            get { return (CameraType) _c_type.GetValueI(); }
            set { _c_type.SetValue((int) value); }
        }

        [Category("Camera")]
        [Description("Camera transformation type")]
        public CameraTransfromType c_transfrom_type
        {
            get { return (CameraTransfromType) _c_transform_type.GetValueI(); }
            set { _c_transform_type.SetValue((int)value); }
        }

        [Category("Camera")]
        [Description("Draw marks for inactive cameras")]
        public bool c_mark
        {
            get { return _c_mark.GetValueB(); }
            set { _c_mark.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Camera mark size")]
        public float c_mark_size
        {
            get { return _c_mark_size.GetValueF(); }
            set { _c_mark_size.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Camera mark color")]
        public Color c_mark_color
        {
            get { return Color.FromArgb(_c_mark_color.GetValueI()); }
            set { _c_mark_color.SetValue(value.ToArgb()); }
        }

        [Category("Camera")]
        [Description("Left")]
        public float c_left
        {
            get { return _c_left.GetValueF(); }
            set { _c_left.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Right")]
        public float c_right
        {
            get { return _c_right.GetValueF(); }
            set { _c_right.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Bottom")]
        public float c_bottom
        {
            get { return _c_bottom.GetValueF(); }
            set { _c_bottom.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Top")]
        public float c_top
        {
            get { return _c_top.GetValueF(); }
            set { _c_top.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Z near")]
        public float c_near
        {
            get { return _c_near.GetValueF(); }
            set { _c_near.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Z far")]
        public float c_far
        {
            get { return _c_far.GetValueF(); }
            set { _c_far.SetValue(value); }
        }

        [Category("Camera")]
        [Description("FOV")]
        public float c_fov_y
        {
            get { return _c_fov_y.GetValueF(); }
            set { _c_fov_y.SetValue(value); }
        }

        [Category("Camera")]
        [Description("Zoom")]
        public float c_zoom
        {
            get { return _c_zoom.GetValueF(); }
            set { _c_zoom.SetValue(Math.Max(value, 0.0f)); }
        }

        [Category("Input")]
        [Description("Mouse sensitivity")]
        public float i_mouse_sensitivity
        {
            get { return _i_mouse_sensitivity.GetValueF(); }
            set { _i_mouse_sensitivity.SetValue(value); }
        }
    }
}
